// src/router/index.ts
import {createRouter, createWebHistory} from 'vue-router'

const routes = [
    {
        path: '/',
        redirect:"/home"
    },
    {
        path: '/main',
        name:"main",
        component:()=>import('@/views/main/index.vue'),
        children: [
            {
                path: '/home',
                name: 'Home',
                component: () => import('@/views/home/index.vue'),
                meta: {title: '首页'}
            },
            {
                path: '/democase',
                name: 'DemoCase',
                component: () => import('@/views/seocase/index.vue'),
                meta: {title: '优化示例'}
            },
            {
                path: '/pricing',
                name: 'Pricing',
                component: () => import('@/views/pricing/index.vue'),
                meta: {title: '定价方案'}
            },
            {
                path: '/help',
                name: 'Help',
                component: () => import('@/views/help/index.vue'),
                meta: {title: '帮助中心'}
            },
        ]
    },
    // {
    //     path: '/login',
    //     name: 'login',
    //     component: () => import('@/views/login.vue'),
    //     meta: {title: '用户登录'}
    // },

]

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes,
    scrollBehavior(to, from, savedPosition) {
        // 路由切换时滚动到顶部
        return {top: 0}
    }
})

// 全局路由守卫示例
router.beforeEach((to, from, next) => {
    // 设置页面标题
    document.title = to.meta.title || 'ResumeAI'
    next()
})

export default router